package com.aisi.manager.controller;

import com.aisi.manager.service.SysRoleService;
import com.aisi.model.dto.system.SysRoleDto;
import com.aisi.model.entity.system.SysRole;
import com.aisi.model.vo.common.Result;
import com.aisi.model.vo.common.ResultCodeEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @Author: shenjianZ
 * @Date: 2024/2/17 10:49
 * @Description:
 */

@RestController
@RequestMapping("/admin/system/sysRole")
public class SysRoleController {

    @Resource
    private SysRoleService sysRoleService;

    @PostMapping("/findByPage/{current}/{limit}")
    public Result findSysRoleByPage(@PathVariable("current") Integer current,
                             @PathVariable("limit") Integer limit,
                             @RequestBody SysRoleDto sysRoleDto) {
        PageInfo<SysRole> rolePageInfo = sysRoleService.findSysRoleByPage(current, limit,sysRoleDto);
        return Result.build(rolePageInfo, ResultCodeEnum.SUCCESS);

    }

    @PostMapping("/saveSysRole")
    public Result saveSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.saveSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @PutMapping("/updateSysRole")
    public Result updateSysRole(@RequestBody SysRole sysRole) {
        sysRoleService.updateSysRole(sysRole);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/deleteSysRoleById/{id}")
    public Result deleteSysRoleById(@PathVariable("id") Long id) {
        sysRoleService.deleteSysRoleById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    @GetMapping("/findAllSysRoles/{userId}")
    public Result findAllSysRoles(@PathVariable("userId") Long userId) {
        Map<String,Object> sysRoleMap = sysRoleService.findAllSysRoles(userId);
        return Result.build(sysRoleMap,ResultCodeEnum.SUCCESS);
    }

}
